package cn.wolfcode.controller;

import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @GetMapping
   public Result list(){
        List<Dept> list = deptService.list();
        return Result.success(list);
    }

    //根据ID查询页面
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        Dept dept = deptService.getById(id);
        return Result.success(dept);
    }
  //修改部门
    @PutMapping
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
   //新增部门
    @PostMapping
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.success();
    }
    //删除部门
    @DeleteMapping({"/{id}"})
    public Result delete(@PathVariable Long id){
        deptService.delete(id);
        return Result.success();
    }

}
